﻿using Net_SCADA.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Net_SCADA
{
    public partial class Form_Top : fdBaseForm
    {
        public int btnWidth=150;
        public int btnHeight=50;
        long _noInputTime;
        public Form_Top()
        {
            InitializeComponent();
        }

        private void Form_Top_Load(object sender, EventArgs e)
        {
            this.Location = netForms.ZeroPoint;
            this.Size=new Size(netForms.bgWidth,60);
            lblTitle.Location = new Point(206, this.Height / 8);
            lblTitle.Size = new Size(this.Width /2, this.Height *3/ 4);
            lblTitle.Font = fdPublicFunction.Getfont(lblTitle.Height ,"微软雅黑",FontStyle.Bold);
            //lblPLCError.Location = new Point(lblTitle.Left+ lblTitle.Width , 2);
            //lblPLCError.Size = new Size(this.Width / 8 - 2, this.Height  - 4);
            //lblPLCError.Font = fdPublicFunction.Getfont(lblTitle.Height/2, "微软雅黑" , FontStyle.Bold);
            btnHeight=btn_Menu.Height = this.Height - 4;
            btnWidth=btn_Menu.Width = btn_Menu.Height * 3;
            btn_Menu.Location = new Point(panel1.Width - 2 - btn_Menu.Width , 2);
            btn_Menu.Font= fdPublicFunction.Getfont(btn_Menu.Height / 2 , "微软雅黑" , FontStyle.Regular);
           // lblTime.Location = new Point(btn_Menu.Left - 5 - lblTime.Width , btn_Menu.Top);
            netForms.fmMenu.Form_Menu_Load(null,null);
            timer1.Enabled = true;
        //    NetLine.NetLine_StartScada();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //显示时间，无操作5分钟后自动退出到数值监视画面
            _noInputTime = fdPublicFunction.GetLastInputTime() / 1000;
            if (_noInputTime > 300)
            {
                fdUsers.UserLogout();
                netForms.Formindex = 0;
            }
            lblTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            lblPLCError.Visible = !NetLine.hslServer.isPlCConnected;
            //显示用户
            if (fdUsers.UserRights > 0)
            {
                if (!lblUsername.Visible)
                {
                    lblUsername.Text = fdUsers.UserName.ToString();
                    lblCaption.Visible= lblUsername.Visible = true;
                }
            }
            else
            {
                if (lblUsername.Visible)
                {
                    lblUsername.Text = "";
                    lblCaption.Visible = lblUsername.Visible = false;
                }
            }
        }

        private void btn_Menu_Click(object sender , EventArgs e)
        {
            if (netForms.fmMenu == null || netForms.fmMenu.IsDisposed)
                netForms.fmMenu = new Form_Menu();
            netForms.fmMenu.Show();
        }

        private void Form_Top_Activated(object sender, EventArgs e)
        {
            if (formLanguageIndex != MultipleLanguage.systemLanguageIndex)
            {
                MultipleLanguage.switchLanguage(this);
                formLanguageIndex = MultipleLanguage.systemLanguageIndex;
            }
        }
    }
}
